//
//  HDCheckLData.m
//  OTIS_MD
//
//  Created by 何达达 on 2017/8/22.
//  Copyright © 2017年 hedada. All rights reserved.
//

#import "HDCheckLData.h"
#import "HDSVTModel.h"
@implementation HDCheckLData
+(BOOL)levelCompreFoolt:(NSMutableArray *)fooltarray level:(NSMutableArray *)levelArray
{   int tip = 0,tip1 = 0;
    if (fooltarray.count == levelArray.count && [self arrayNoRepeat:fooltarray]) {
        tip = 1;
    }
    for (int i = 0; i < fooltarray.count ; i++) {
        if ([levelArray containsObject:fooltarray[i]]) {
            tip1 = 1;
        }else{
            tip1 = 0;
            break;
            
        }
    }
    if (tip && tip1) {
        return YES;
    }
    return NO;
}
+(BOOL)arrayNoRepeat:(NSMutableArray *)array{
    int tip = 0;
    for (int  i = 0; i < array.count; i++) {
        for (int j = 0; j < array.count; j++) {
            if (array[i] == array[j]) {
                tip++;
            }
        }
    }
    if (tip == 2) {
        return NO;
    }
    return YES;

}
+(BOOL)LdataJsonCheck:(Ldata *)ldata{
    

    if ([self ldataPropertyIsComplete:ldata] == MDJSONLdataTypeDefult) {
        return YES;
    }
    return NO;
    
}
+(MDJSONLdataType)ldataPropertyIsComplete:(Ldata *)ldata
{
    if ([self CNT_DCheck:ldata.CNT_D] == MDJSONLdataTypeNotCompleted) {
        return MDJSONLdataTypeNotCompleted;
    }
    if ([self LastTSCheck:ldata.LastTS] == MDJSONLdataTypeNotCompleted) {
        return MDJSONLdataTypeNotCompleted;
    }
    if ([self LatchedCountCheck:ldata.LatchedCount] == MDJSONLdataTypeNotCompleted) {
        return MDJSONLdataTypeNotCompleted;
    }
    if ([self LCheck:ldata.L] == MDJSONLdataTypeNotCompleted) {
        return MDJSONLdataTypeNotCompleted;
    }
    if ([self G_CNTCheck:ldata.L] == MDJSONLdataTypeNotCompleted) {
        return MDJSONLdataTypeNotCompleted;
    }
    if ([self Y_CNTCheck:ldata.L] == MDJSONLdataTypeNotCompleted) {
        return MDJSONLdataTypeNotCompleted;
    }
    if ([self R_CNTCheck:ldata.L] == MDJSONLdataTypeNotCompleted) {
        return MDJSONLdataTypeNotCompleted;
    }
    if ([self G_CNT_RCheck:ldata.L] == MDJSONLdataTypeNotCompleted) {
        return MDJSONLdataTypeNotCompleted;
    }
    
    if ([self Y_CNT_RCheck:ldata.L] == MDJSONLdataTypeNotCompleted) {
        return MDJSONLdataTypeNotCompleted;
    }
    if ([self R_CNT_RCheck:ldata.L] == MDJSONLdataTypeNotCompleted) {
        return MDJSONLdataTypeNotCompleted;
    }
    
    return MDJSONLdataTypeDefult;
    
}

//对ldata中的L数组L元素进行检查
+(MDJSONLdataType)LCheck:(NSArray <L*>*)l{
    
    for (int i = 0; i < l.count; i++) {
        L *L = l[i];
        if (L.L.intValue == i) {
            
        }else{
            return MDJSONLdataTypeNotCompleted;
        }
        
    }
    return MDJSONLdataTypeDefult;
    
}
//对G_CNT的检查
+(MDJSONLdataType)G_CNTCheck:(NSArray <L*>*)l{
    
    for (int i = 0; i < l.count; i++) {
        L *L = l[i];
        if ([self hexadecimalCheck:L.G_CNT]) {
            
        }else{
            return MDJSONLdataTypeNotCompleted;
        }
        
    }
    return MDJSONLdataTypeDefult;

}

//对G_CNT的检查
+(MDJSONLdataType)Y_CNTCheck:(NSArray <L*>*)l{
    
    for (int i = 0; i < l.count; i++) {
        L *L = l[i];
        if ([self hexadecimalCheck:L.Y_CNT]) {
            
        }else{
            return MDJSONLdataTypeNotCompleted;
        }
        
    }
    return MDJSONLdataTypeDefult;
    
}

//对R_CNT的检查
+(MDJSONLdataType)R_CNTCheck:(NSArray <L*>*)l{
    
    for (int i = 0; i < l.count; i++) {
        L *L = l[i];
        if ([self hexadecimalCheck:L.R_CNT]) {
            
        }else{
            return MDJSONLdataTypeNotCompleted;
        }
        
    }
    return MDJSONLdataTypeDefult;
    
}

//对G_CNT_R的检查
+(MDJSONLdataType)G_CNT_RCheck:(NSArray <L*>*)l{
    
    for (int i = 0; i < l.count; i++) {
        L *L = l[i];
        if ([self hexadecimalCheck:L.G_CNT_R]) {
            
        }else{
            return MDJSONLdataTypeNotCompleted;
        }
        
    }
    return MDJSONLdataTypeDefult;
    
}

//对Y_CNT_R的检查
+(MDJSONLdataType)Y_CNT_RCheck:(NSArray <L*>*)l{
    
    for (int i = 0; i < l.count; i++) {
        L *L = l[i];
        if ([self hexadecimalCheck:L.Y_CNT_R]) {
            
        }else{
            return MDJSONLdataTypeNotCompleted;
        }
        
    }
    return MDJSONLdataTypeDefult;
    
}

//对R_CNT_R的检查
+(MDJSONLdataType)R_CNT_RCheck:(NSArray <L*>*)l{
    
    for (int i = 0; i < l.count; i++) {
        L *L = l[i];
        if ([self hexadecimalCheck:L.R_CNT_R]) {
            
        }else{
            return MDJSONLdataTypeNotCompleted;
        }
        
    }
    return MDJSONLdataTypeDefult;
    
}
//判断一个字符串是不是十六进制
+(BOOL)hexadecimalCheck:(NSString *)string{
    
    NSString *regex = @"\b0[xX][0-9a-fA-F]+\b";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
    if ([pred evaluateWithObject:string]) {
        return YES;
    }
    return NO;
    
}
//
//对CNT_D的检查
+(MDJSONLdataType)CNT_DCheck:(NSString *)CNT_D{
    if ([self stringIsNum:CNT_D] && CNT_D.length == 6) {
        return MDJSONLdataTypeDefult;
    }
    return MDJSONLdataTypeNotCompleted;
}

//对LastTS的检查
+(MDJSONLdataType)LastTSCheck:(NSString *)LastTS{
    if ([self stringIsNum:LastTS] && LastTS.length == 11) {
        return MDJSONLdataTypeDefult;
    }
    return MDJSONLdataTypeNotCompleted;
}

//对LatchedCount的检查
+(MDJSONLdataType)LatchedCountCheck:(NSString *)LatchedCount{
    if ([self stringIsNum:LatchedCount] && LatchedCount.length == 8) {
        return MDJSONLdataTypeDefult;
    }
    return MDJSONLdataTypeNotCompleted;
}

//正则表达式判断一个字符串是否是纯数字
+(BOOL)stringIsNum:(NSString *)string{
    NSString *regex = @"[0-9]*";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
    if ([pred evaluateWithObject:string]) {
        return YES;
    }
    return NO;
    
}

@end
